package leetcode;

import java.util.ArrayList;
import java.util.List;

public class LeetCode22 {


    //任意情况 添加前括号
    //前括号个数大于后扩号 可以添加后扩号
    List<String> result = new ArrayList<>();

    public List<String> generateParenthesis(int n) {
        calculation(n, n, "");
        return result;
    }

    private void calculation(int frontCount, int backCount, String str) {
        if (frontCount == 0 && backCount == 0) {
            result.add(str);
            return;
        }
        if (frontCount > 0)
            calculation(frontCount - 1, backCount, str + "(");
        if (frontCount < backCount)
            calculation(frontCount, backCount - 1, str + ")");
    }
//------------------------------------------------------------------
}
